package test2;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",9999);
        Scanner sc = new Scanner(System.in);
        OutputStream os = socket.getOutputStream();
        System.out.println("输入发出的消息:");
        String str = sc.nextLine();
        os.write(str.getBytes());
        socket.shutdownOutput();
        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int b;
        while((b = isr.read()) != -1) {
            System.out.print((char)b);
        }
        socket.close();
    }
}
